package common;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import action.PictureController;
import action.UserController;

import com.xiaoleilu.hutool.Log;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException{
		PropertyConfigurator.configure( "bin/config/log4j.properties " );      
		final ServerSocket server = new ServerSocket(9090);
		Log.debug("创建服务器成功，监听端口9090");
		configRouter();
		Log.debug("maping-->{}", HandlerMapping.getRouterKey());
		new Thread(new Runnable(){

			public void run() {
				while(true){
					Socket socket = null;
					try {
						socket = server.accept();
						Log.debug("接受一个客户端连接:");
						ServerThread st = new ServerThread(socket);
						st.process();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}	
				
			}
			
		}).start();
		
	}
	
	public static void configRouter(){
		HandlerMapping.addRouter("picture", PictureController.class);
		HandlerMapping.addRouter("user", UserController.class);
	}

}
